package com.housekeeping.housekeeping.cleanerInformation.controller;

import com.housekeeping.housekeeping.cleanerInformation.entity.Cleaner;
import com.housekeeping.housekeeping.cleanerInformation.service.ICleanerService;
import com.housekeeping.housekeeping.cleanerInformation.service.impl.CleanerServiceImpl;
import com.housekeeping.housekeeping.cleanerInformation.utils.Page;
import com.housekeeping.housekeeping.cleanerInformation.utils.ResponseEntity;
import com.housekeeping.housekeeping.cleanerInformation.utils.ResponseUtils;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.SQLException;

/**
 * @author hua
 * @version JDK1.8
 * @date 2021/1/19 10:11
 *      分页查询
 */
@WebServlet("/cleanerInformation/controller/CleanerSelectController")
public class CleanerSelectController extends HttpServlet {
    private ICleanerService cleanerService = new CleanerServiceImpl();
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //设置请求字符集
        request.setCharacterEncoding("utf-8");
        //设置响应字符集
        response.setContentType("text/html;charset=utf-8");
        //获取前端发送当前页数和每页的数据条数
        int page = Integer.parseInt(request.getParameter("page"));
        int size = Integer.parseInt(request.getParameter("size"));

        ResponseEntity<Page<Cleaner>> entity = null;

        Page<Cleaner> pageBan = null;
        try {
            pageBan = cleanerService.list(page,size);
            entity = ResponseEntity.success(pageBan);
        } catch (SQLException throwables) {
            entity = ResponseEntity.error(404, "系统异常! 请稍后再试");
        }
        ResponseUtils.resp(response,entity);
    }
}
